package com.zztl.infiniteBand.ui.activity

import android.support.v7.widget.LinearLayoutManager
import com.andview.refreshview.XRefreshView
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.adapter.InviteIncomeAdapter
import com.zztl.infiniteBand.base.BaseMvpActivity
import com.zztl.infiniteBand.model.BaseResponseBean
import com.zztl.infiniteBand.model.InviteIncomeBean
import com.zztl.infiniteBand.net.requestBean.InviteIncomeRequest
import com.zztl.infiniteBand.presenter.InviteIncomePresenter
import com.zztl.infiniteBand.ui.view.mvpview.RankingListView
import com.zztl.infiniteBand.ui.view.recycleview.SimpleItemDecoration
import kotlinx.android.synthetic.main.activity_invite_detail.*

class InviteIncomeActivity : BaseMvpActivity<RankingListView, InviteIncomePresenter>(), RankingListView {
/*    @BindView(R.id.recycleView)
    lateinit var recycleView: RecyclerView
    @BindView(R.id.xrefreshview)
    lateinit var xRefreshView: XRefreshView*/

    private var mList: List<InviteIncomeBean.DataBean>? = null
    private var mIncomeAdapter: InviteIncomeAdapter? = null
    lateinit var mIncomePresenter: InviteIncomePresenter
    lateinit var mIncomeRequest: InviteIncomeRequest

    override fun setLayoutId(): Int = R.layout.activity_invite_detail


    override fun initBase() {
        mList = arrayListOf()
        setTitle(getString(R.string.邀请注册收益))
        initRecyclerView()
        mIncomeRequest = InviteIncomeRequest("1", "UIfDJPdn")
        mIncomePresenter.getInviteIncome(mIncomeRequest, this)
    }

    private fun initRecyclerView() {
       /* recycleView.layoutManager = LinearLayoutManager(this)
        recycleView.addItemDecoration(SimpleItemDecoration(this))
        mIncomeAdapter = InviteIncomeAdapter(R.layout.item_inviteincomel, mList)*/

        recycleView.let {
            it.layoutManager = LinearLayoutManager(this)
            it.addItemDecoration(SimpleItemDecoration(this))
            mIncomeAdapter = InviteIncomeAdapter(R.layout.item_inviteincomel, mList).apply {
                it.adapter = this
            }
        }


        xrefreshview.let {
            it.setPinnedTime(800)
            it.setAutoLoadMore(false)
            it.pullLoadEnable = false
            it.setXRefreshViewListener(object : XRefreshView.SimpleXRefreshListener() {
                override fun onRefresh(isPullDown: Boolean) {
                    mIncomePresenter.getInviteIncome(mIncomeRequest, this@InviteIncomeActivity)

                }

                override fun onLoadMore(isSilence: Boolean) {

                }
            })
        }

    }

    override fun createPresenter(): InviteIncomePresenter {
        mIncomePresenter = InviteIncomePresenter().apply {  }
        return mIncomePresenter
    }


    override fun getListSuccess(bean: BaseResponseBean<*>) {
        val incomeBean = bean as InviteIncomeBean
        mIncomeAdapter!!.setNewData(incomeBean.data)

    }

    override fun stopRefershOrLoad() {
        xrefreshview.let {
            it.stopRefresh()
            it.stopLoadMore(true)
        }
    }
}
